home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / puttips.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  83 lines

  1. pro putTips, $
  2.     sText, $        ; IN: text structure (fields : id, text)
  3.     widgetID, $     ; IN: widget text identifier
  4.     textArray, $    ; IN: string array to change from current settings.
  5.     position        ; IN: integer array position of each text changes.
  6.                     ;     Dimensions of textArray and position are the same.
  7.  
  8.  
  9.     ;  Verify the validity of the input parameters.
  10.     ;
  11.     if (N_PARAMS() NE 4) then begin
  12.         PRINT,' Error in putTips.pro : you must pass 4 parameters.'
  13.         RETURN
  14.     endif
  15.  
  16.     if (  WIDGET_INFO(widgetID, /NAME) NE 'TEXT') then begin
  17.         PRINT, 'Error in putTips.pro : WidgetID is not a widget text.'
  18.         RETURN
  19.     endif
  20.     if ( WIDGET_INFO(widgetID, /VALID_ID) EQ 0) then begin
  21.         PRINT, 'Error in putTips.pro : widget text ID not valid.'
  22.         RETURN
  23.     endif
  24.  
  25.     sizeText = size(textArray)
  26.  
  27.     if ( (sizeText[2] NE 7) OR (sizeText[0] NE 1) ) then begin
  28.         PRINT, 'Error in putTips.pro : text array must be a string array'
  29.         PRINT, 'and must be one dimensional.'
  30.         RETURN
  31.     endif
  32.         
  33.     sizePosition = size(position)
  34.     if ( (sizePosition[2] NE 2) OR (sizePosition[0] NE 1) ) then begin
  35.         PRINT, 'Error in putTips.pro : positon array must be an '
  36.         PRINT, 'integer array and must be one dimensional.'
  37.         RETURN
  38.     endif
  39.  
  40.     ;  Get the number of changes to make.
  41.     ;
  42.     nChange = N_ELEMENTS(textArray)
  43.  
  44.     ;  Get the existing text in the widget text.
  45.     ;
  46.     WIDGET_CONTROL, widgetID, GET_VALUE=widgetText
  47.  
  48.     ;  For the demo purpose only, we must assure that
  49.     ;  there are 3 text lines  within the widget text.
  50.     ;  There may be cases where there are only 1 or
  51.     ;  2 lines returned from the get_value call above.
  52.     ;
  53.     nLinesText = N_ELEMENTS(widgetText)
  54.     maxLines = 3
  55.     if (nLinesText LT maxLines) then $
  56.         widgetText = [widgetText, STRARR(maxLines-nLinesText)]
  57.  
  58.     ;  Make sure that the position is less that 3 (0,1, or 2).
  59.     ;  For demo purpose only.
  60.     ;
  61.     if (MAX(position) GE maxLines) then begin
  62.         PRINT,'Error in puttips : the position must be less than '+ $
  63.            STRING(maxLines)
  64.         RETURN
  65.     endif
  66.  
  67.     ;  Make the changes.
  68.     ;
  69.     for j = 0, nChange-1 do begin
  70.         flag = 0
  71.         i = 0
  72.         while ( flag EQ 0) do begin
  73.             if (sText.id[i] EQ textArray[j]) then begin
  74.                 widgetText[position[j]] = sText.text[i]
  75.                 flag = 1
  76.             endif
  77.                 i = i+1
  78.         endwhile
  79.     endfor
  80.     WIDGET_CONTROL, widgetID, SET_VALUE=widgetText
  81.  
  82. end     ; of putTips
  83.